<?php
namespace Home\Service;

use Think\Service\BasicService;

class DataUpdateService extends BasicService {
    public function insert($model) {
        return $this->db->add($model);
    }

    public function remove($condition) {
        return $this->db->where($condition)->delete();
    }

    public function update($model) {
        return $this->db->save($model);
    }

    public function find($condition) {
        return $this->db->where($condition)->find();
    }

    public function querySQL($sql) {
        $Model = M();
        return $Model->query($sql);
    }

    public function query($condition, $field = null) {
        $data = $this->db->field($field)->where($condition)
//            ->limit(500)
            ->order('created_time desc')->select();
        return $data;
    }

    public function AddAll($model) {
        $this->db->startTrans();
        $DELOK = $this->db->where('1')->delete();
        if ($DELOK) {
            $ADDOK = $this->db->addAll($model);
            if ($ADDOK) {
                $this->db->commit();
                return 1;
            }
        }
        $this->db->rollback();
        return 0;
    }

}

?>